package com.example.baidu.speech.realtime.sdk.download;

import com.alibaba.fastjson2.JSON;
import com.example.baidu.speech.realtime.sdk.util.Stat;
import com.example.baidu.speech.realtime.websocket.BaiduSpeechRealtimeWebSocket;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * STEP 2.3 库接收识别结果
 *
 * @author hspcadmin
 */
@Slf4j
@AllArgsConstructor
public class SimpleDownloader {

    /**
     * 个人扩展webSocketId，为了把消息发送到指定客户端
     */
    private String webSocketId;

    public void onMessage(Result result) {
        if (!result.isHeartBeat()) {
            log.info(Stat.formatResult(result).toString());
            // 将百度实时语音识别API的结果，发送给对应的客户端
            BaiduSpeechRealtimeWebSocket.replyMessage(webSocketId, JSON.toJSONString(result));
        }
    }
}
